package com.adinnet.api.childStudyRecord.controller;

import com.adinnet.api.childStudyRecord.model.vo.ChildStudyRecordReq;
import com.adinnet.api.childStudyRecord.model.vo.StudyRecordsListReq;
import com.adinnet.api.childStudyRecord.service.ChildStudyRecordService;
import com.adinnet.api.common.utils.AvoidReSubmit;
import com.adinnet.core.JsonResult;
import com.adinnet.core.exception.BizException;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 * 儿童学习记录表 前端控制器
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-07
 */
@RestController
@RequestMapping("/api/childStudyRecord")
public class ChildStudyRecordController {

    @Autowired
    private ChildStudyRecordService childStudyRecordService;

    /**
     * 学习视频/音频
     *
     * @return
     */
    @PostMapping("videoOrAudio")
    public JsonResult videoOrAudio(@Valid @RequestBody ChildStudyRecordReq studyRecordReq) {
        try {

            return  childStudyRecordService.videoOrAudio(studyRecordReq);
        } catch (BizException e) {
            return JsonResult.error(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error("操作失败！");
        }
    }

    /**
     * 批量上传学习词汇/短句记录
     *  2021-01-06 IOS无法传json数组形式的参数，故修改成json实体的参数
     *  2021-01-14 单词和短句的学习逻辑修改，可以只传学习时长，不传学习记录集合
     * @return
     */
    @PostMapping("uploadWordOrSentenceStudyRecords")
    @AvoidReSubmit(expireTime = 5000)
    public JsonResult uploadWordOrSentenceStudyRecords(@Valid @RequestBody StudyRecordsListReq reqs) {
        try {
            Integer totalNum=childStudyRecordService.uploadWordOrSentenceStudyRecords(reqs);
            return JsonResult.ok().put("data",totalNum);
        } catch (BizException e) {
            return JsonResult.error(e.getMessage());
        } catch (Exception e) {
            return JsonResult.error("操作失败！");
        }
    }

}
